home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / wsanet8a / wsanet / src / netclnt.c < prev    next >
C/C++ Source or Header  |  1996-04-08  |  64KB  |  2,204 lines

  1. /* NetClnt.C - WinSock NetClient Control for VB/VC++
  2.   - WinSock V1.1 required
  3.   - Visual Basic 1.0 required, 2.0+ preferred (tested only on 3.0)
  4.  
  5.    Author: Ian Blenke
  6.  
  7. In this document, VBX refers to the actual Visual Basic control distributed
  8. with and based on this WSANET project, and author refers to Ian Blenke. The
  9. author cannot be held responsible for damages, expressed or implied, for the
  10. use of this software. No commercial use can be made of this product without
  11. the consent of the author. No profit of any kind can be made on the sale or
  12. distribution of this program. If you wish to distribute this program with
  13. other samples of WinSock programming, you must first contact the author so
  14. that he can keep accurate records of its usage; no charge may be made for
  15. this project's availability other than the cost of the physical medium used
  16. to store it on and any processing costs. If you writany programs based on
  17. this source code, including parts of this source code, or in some way derived
  18. from this source code, you may not sell them for any profit without the
  19. written consent of the author. If you incorporate this VBX into a public
  20. dain program althe author requires is a notification that "The NetClient
  21. control was written by Ian Blenke" and some form of notification that his name
  22. was used in the public domain software distribution. No profit of any kind,
  23. shareware/commercial or otherwise, may be made for software based on this VBX
  24. without the written consent of the author. This does not represent a contract
  25. on the part of the author. If any issues cannot clearly be resolved by reading
  26. this text, immediately contact the author.
  27.  
  28. The VBX control distributed with this project must be distributed with your
  29. programs free of charge. You cannot charge money for any program based on the
  30. VBX without the written consent of the author.
  31.  
  32. Notes:
  33.  
  34. If you have any bug reports and/or source patches... By all means, tell me! I
  35. would be glad to help keep this code up to date. Do not, however, modify this
  36. source in any way and re-distribute it without the author's knowledge. Follow
  37. the above Copyright, and all will be well.
  38.  
  39. I don't like such agreements, but in today's world of lawyers and lawbreakers,
  40. I have little other choice. Enjoy!
  41.  
  42. (This is meant to scare code "scalpers". Those that are actually learning C
  43.  programming for Visual Basic controls and WinSock applications are free to
  44.  adapt any of the ideas of this code. Remember, new code should be better
  45.  code, so "adapt" this, do NOT copy it.)
  46. */
  47.  
  48. #define NetClnt_C
  49. #include "WSANet.H"
  50. #include "NetClnt.H"
  51.  
  52.     // Specific globals to NetClnt.C
  53. static char szLocalHostName[256];       // Name of the machine running us
  54.  
  55. #ifdef DEBUG_BUILD
  56. static char szErrors[256];
  57.  
  58. VOID DEBUGNETC(LPSTR lpString)
  59. {
  60.  wsprintf((LPSTR)szErrors, (LPSTR)"NetClient: %s\n\r", lpString);
  61.  OutputDebugString( (LPSTR)szErrors );
  62. }
  63. #else
  64. #define DEBUGNETC( parm )
  65. #endif /* DEBUG_BUILD */
  66.  
  67.  
  68. /* LONG CALLBACK _export NetClientCtlProc(HCTL, HWND, UINT, WPARAM, LPARAM);
  69.     Purpose: To handle the VBX messages
  70. */
  71. LONG CALLBACK _export NetClientCtlProc(HCTL hCtl, HWND hWnd, UINT Msg,
  72.                                        WPARAM wParam, LPARAM lParam)
  73. {
  74.  LPNETCLIENT lpNetClient;
  75.  
  76.  lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  77.  
  78.  switch(Msg)
  79.  {
  80.  
  81. #ifdef DESIGN_TIME
  82.     // The MODEL want's to know our default size
  83.   case VBM_GETDEFSIZE:
  84.   {
  85.    BITMAP bmp;
  86.    HBITMAP hBitmap;
  87.  
  88.    DEBUGNETC("VBM_GETDEFSIZE[2.0] Begin\n\r");
  89.    hBitmap=LoadBitmap(hModDLL, MAKEINTRESOURCE(IDBMP_CLIENT));
  90.    if(hBitmap)
  91.    {
  92.     GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bmp);
  93.     DeleteObject(hBitmap);
  94.     DEBUGNETC((LPSTR)"VBM_GETDEFSIZE[2.0] End\n\r");
  95.     return(MAKELONG(bmp.bmWidth, bmp.bmHeight));
  96.    }
  97.    DEBUGNETC((LPSTR)"VBM_GETDEFSIZE[2.0] Allowing DefVBProc to handle\n\r");
  98.   }
  99.   break;
  100.  
  101.     // The re-size message - only in design time
  102.   case WM_SIZE:
  103.   {
  104.    BITMAP bmp;
  105.    HBITMAP hBitmap;
  106.    RECT rect;
  107.    POINT pos;
  108.  
  109.    DEBUGNETC((LPSTR)"WM_SIZE Start");
  110.    GetWindowRect(hWnd, (RECT FAR *)&rect);
  111.    pos.x=rect.left;
  112.    pos.y=rect.top;
  113.    ScreenToClient((HWND)GetWindowWord(hWnd, GWW_HWNDPARENT),
  114.                   (POINT FAR *)&pos);
  115.  
  116.    hBitmap=LoadBitmap(hModDLL, MAKEINTRESOURCE(IDBMP_CLIENT));
  117.    if(hBitmap)
  118.    {
  119.     GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bmp);
  120.     MoveWindow(hWnd, pos.x, pos.y, bmp.bmWidth, bmp.bmHeight,
  121.                SWP_NOZORDER | SWP_NOMOVE);
  122.     DeleteObject(hBitmap);
  123.     DEBUGNETC((LPSTR)"WM_SIZE End");
  124.     return(0);
  125.    }
  126.    DEBUGNETC((LPSTR)"WM_SIZE End - Bitmap load failure!");
  127.   }
  128.   break;
  129.  
  130.  
  131.     // The paint message - only design time!
  132.   case WM_PAINT:
  133.   {
  134.    PAINTSTRUCT ps;
  135.    BITMAP bmp;
  136.    RECT rect;
  137.    HBITMAP hBitmap,
  138.            hOldBitmap;
  139.    HDC  hdcMem;
  140.  
  141.    DEBUGNETC((LPSTR)"WM_PAINT Start");
  142.    if(VBGetMode()==MODE_RUN) break;
  143.  
  144.    GetWindowRect(hWnd, (RECT FAR *)&rect);
  145.    BeginPaint(hWnd, (PAINTSTRUCT FAR *)&ps);
  146.    hBitmap=LoadBitmap(hModDLL, MAKEINTRESOURCE(IDBMP_CLIENT));
  147.    if(hBitmap)
  148.    {
  149.     GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bmp);
  150.     hdcMem = CreateCompatibleDC(ps.hdc);
  151.     if(hdcMem)
  152.     {
  153.      hOldBitmap=SelectObject(hdcMem, hBitmap);
  154.      BitBlt(ps.hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcMem,
  155.             0, 0, SRCCOPY);
  156.      SelectObject(hdcMem, hOldBitmap);
  157.      DeleteDC(hdcMem);
  158.     }
  159.     DeleteObject(hBitmap);
  160.    }
  161.    EndPaint(hWnd, (PAINTSTRUCT FAR *)&ps);
  162.    DEBUGNETC((LPSTR)"WM_PAINT End");
  163.   }
  164.   break;
  165. #endif // DESIGN_TIME
  166.  
  167.  
  168.     // The control is closing - free everything.
  169.   case WM_NCDESTROY:
  170.   {
  171.    DEBUGNETC((LPSTR)"WM_NCDESTROY Begin");
  172.  
  173.     // If there is still a LineDelimiter string, destroy it
  174.    if(lpNetClient->hszLineDelimiter)
  175.    {
  176.     VBDestroyHsz(lpNetClient->hszLineDelimiter);
  177.     lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  178.     lpNetClient->hszLineDelimiter=NULL;
  179.    }
  180.  
  181.     // If there is still a RawLineDelimiter string, destroy it
  182.    if(lpNetClient->hszRawLineDelimiter)
  183.    {
  184.     VBDestroyHsz(lpNetClient->hszRawLineDelimiter);
  185.     lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  186.     lpNetClient->hszRawLineDelimiter=NULL;
  187.    }
  188.  
  189.     // If there is still a SendBlock string, destroy it
  190.    if(lpNetClient->hlSendBlock)
  191.    {
  192.     VBDestroyHlstr(lpNetClient->hlSendBlock);
  193.     lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  194.     lpNetClient->hlSendBlock=0;
  195.    }
  196.  
  197.     // If there is still a RecvBlock string, destroy it
  198.    if(lpNetClient->hlRecvBlock)
  199.    {
  200.     VBDestroyHlstr(lpNetClient->hlRecvBlock);
  201.     lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  202.     lpNetClient->hlRecvBlock=NULL;
  203.    }
  204.  
  205.      // If there is still a RecvBuffer area, destroy it
  206.    if(lpNetClient->hRecvBuffer)
  207.    {
  208.     GlobalUnlock(lpNetClient->hRecvBuffer);
  209.     GlobalFree(lpNetClient->hRecvBuffer);
  210.     lpNetClient->hRecvBuffer=0;
  211.     lpNetClient->lpRecvBuffer=NULL;
  212.     lpNetClient->sRecvCount=0;
  213.    }
  214.  
  215.      // If there is still a SendBuffer area, destroy it
  216.    if(lpNetClient->hSendBuffer)
  217.    {
  218.     GlobalUnlock(lpNetClient->hSendBuffer);
  219.     GlobalFree(lpNetClient->hSendBuffer);
  220.     lpNetClient->hSendBuffer=0;
  221.     lpNetClient->lpSendBuffer=NULL;
  222.     lpNetClient->sSendCount=0;
  223.    }
  224.  
  225.      // If there is still a RecvTemp area, destroy it
  226.    if(lpNetClient->hRecvTemp)
  227.    {
  228.     GlobalUnlock(lpNetClient->hRecvTemp);
  229.     GlobalFree(lpNetClient->hRecvTemp);
  230.     lpNetClient->lpRecvTemp=NULL;
  231.     lpNetClient->hRecvTemp=0;
  232.     lpNetClient->sRecvTempSize=0;
  233.    }
  234.  
  235.      // If there is still a SendTemp area, destroy it
  236.    if(lpNetClient->hSendTemp)
  237.    {
  238.     GlobalUnlock(lpNetClient->hSendTemp);
  239.     GlobalFree(lpNetClient->hSendTemp);
  240.     lpNetClient->hSendTemp=0;
  241.     lpNetClient->lpSendTemp=NULL;
  242.     lpNetClient->sSendTempSize=0;
  243.    }
  244.  
  245.     // If the HostAddresses() list was full, delete it
  246.    if(lpNetClient->htHostAddressList.iHostCount)
  247.    {
  248.     int iCounter;
  249.     MOLE mTemp;
  250.  
  251.     for(iCounter=0;iCounter<(lpNetClient->htHostAddressList.iHostCount);
  252.         iCounter++)
  253.     {
  254.      mTemp = lpNetClient->htHostAddressList.mHost[iCounter];
  255.      DeleteMole(mTemp);
  256.      lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  257.      lpNetClient->htHostAddressList.mHost[iCounter] = 0;
  258.     }
  259.     lpNetClient->htHostAddressList.iHostCount = 0;
  260.    }
  261.  
  262.     // If the HostAliases() list was full, delete it
  263.    if(lpNetClient->htHostAliasList.iHostCount)
  264.    {
  265.     int iCounter;
  266.     MOLE mTemp;
  267.  
  268.     for(iCounter=0;iCounter<(lpNetClient->htHostAliasList.iHostCount);
  269.         iCounter++)
  270.     {
  271.      mTemp = lpNetClient->htHostAliasList.mHost[iCounter];
  272.      DeleteMole(mTemp);
  273.      lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  274.      lpNetClient->htHostAliasList.mHost[iCounter] = 0;
  275.     }
  276.     lpNetClient->htHostAliasList.iHostCount = 0;
  277.    }
  278.  
  279.      // If there is still a live connection, hang up
  280.    if(lpNetClient->sSocket!=SOCKET_ERROR)
  281.    {
  282.     netCloseSocket(hWnd, lpNetClient->sSocket);
  283.     lpNetClient->bConnect=FALSE;
  284.     lpNetClient->sSocket=(SOCKET)SOCKET_ERROR;
  285.    }
  286.    DEBUGNETC((LPSTR)"WM_NCDESTROY End");
  287.   }
  288.   break; // WM_NCDESTROY
  289.  
  290.  
  291.     // Another control was created, initialize the pieces
  292.   case VBM_CREATED:
  293.   {
  294.    LPHOSTENT lpheHost;
  295.    int iError;
  296.    char cChar;
  297.    HSZ hszTempOne,
  298.        hszTempTwo;
  299.    int iCounter;
  300.    LPSTR lpTemp;
  301.    LPSTR FAR *lppTemp;
  302.    MOLE mTemp;
  303.  
  304.    DEBUGNETC((LPSTR)"VBM_CREATED Begin");
  305.  
  306.     // Haven't received anything YET! ;)
  307.    lpNetClient->sRecvCount=0;
  308.    lpNetClient->sSendCount=0;
  309.  
  310.     // These are allocated upon a FD_CONNECT
  311.     // and destroyed by a WM_NCDESTROY
  312.    lpNetClient->sRecvTempSize=0;
  313.    lpNetClient->sSendTempSize=0;
  314.    lpNetClient->hRecvTemp=0;
  315.    lpNetClient->hSendTemp=0;
  316.    lpNetClient->lpRecvTemp=NULL;
  317.    lpNetClient->lpSendTemp=NULL;
  318.  
  319.     // Alpha #3 feature, Flag waiting for FD_WRITE
  320.    lpNetClient->fCanSend=FALSE;
  321.  
  322.     // Alpha #6 feature, Multiple aliases and addresses
  323.    lpNetClient->htHostAddressList.iHostCount = 0;
  324.    lpNetClient->htHostAliasList.iHostCount = 0;
  325.  
  326.     // HostName/HostAddr MOLE initialization (Alpha #6)
  327.    lpNetClient->mHostName = 0;
  328.    lpNetClient->mHostAddr = 0;
  329.  
  330.     // Setup a "null string" to point to
  331.    cChar='\0';
  332.  
  333.     // If there was no default line delimiter, make a null one
  334.    if(!lpNetClient->hszLineDelimiter)
  335.    {
  336.     hszTempOne=VBCreateHsz((_segment)hCtl, (LPSTR)&cChar);
  337.     hszTempTwo=VBCreateHsz((_segment)hCtl, (LPSTR)&cChar);
  338.  
  339.     lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  340.     lpNetClient->hszRawLineDelimiter=hszTempOne;
  341.     lpNetClient->hszLineDelimiter=hszTempTwo;
  342.  
  343.     DEBUGNETC((LPSTR)"VBM_CREATED Created empty LineDelimiter strings");
  344.    }
  345.    else
  346.    {
  347.     char szBuffer[256];
  348.     HSZ  hszTemp;
  349.     LPSTR lpDelim;
  350.     LPSTR lpRaw;
  351.  
  352.     DEBUGNETC((LPSTR)"VBM_CREATED Building RawDelimiter string");
  353.         // There is a default one: Make our raw string
  354.     hszTemp=lpNetClient->hszLineDelimiter;
  355.     lpDelim=VBDerefHsz(hszTemp);
  356.  
  357.     lpRaw=(LPSTR)szBuffer;
  358.     while(*lpDelim)
  359.     {
  360.      if( (*lpDelim=='\\') && *(lpDelim+1))
  361.      {
  362.       lpDelim++;
  363.       switch(*lpDelim)
  364.       {
  365.        case 'n':
  366.        *lpRaw++='\n';
  367.         lpDelim++;
  368.        break;
  369.  
  370.        case 't':
  371.        *lpRaw++='\t';
  372.         lpDelim++;
  373.        break;
  374.  
  375.        case 'r':
  376.        *lpRaw++='\r';
  377.         lpDelim++;
  378.        break;
  379.  
  380.        default:
  381.        *lpRaw++=*lpDelim++;
  382.        break;
  383.       }
  384.      }
  385.      else *lpRaw++=*lpDelim++;
  386.     }
  387.     *lpRaw='\0';
  388.  
  389.     hszTempOne=VBCreateHsz((_segment)hCtl, (LPSTR)szBuffer);
  390.     if(!hszTempOne)
  391.     {
  392.      hszTempOne=VBCreateHsz((_segment)hCtl, (LPSTR)&cChar);
  393.     }
  394.  
  395.     lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  396.     lpNetClient->hszRawLineDelimiter=hszTempOne;
  397.    }
  398.  
  399.     // This pretty much be-rids us of MODEL_fInvisAtRun
  400.    if(VBGetMode()==MODE_RUN)
  401.    {
  402.     ShowWindow(hWnd, SW_HIDE);
  403.    }
  404.    else
  405.    {
  406.     ShowWindow(hWnd, SW_SHOWNA);
  407.    }
  408.  
  409.    lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  410.  
  411.    DEBUGNETC((LPSTR)"VBM_CREATED Marker #7");
  412.  
  413.     // Initialize the timeout
  414.    lpNetClient->sTimeOutStore=lpNetClient->sTimeOut;
  415.  
  416.        // Initialize the other properties
  417.    lpNetClient->sSocket = (SOCKET)SOCKET_ERROR;
  418.    lpNetClient->bConnect= FALSE;
  419.    lpNetClient->sErrorNumber = 0;
  420.  
  421.    if(!lpNetClient->sSendSize)
  422.         lpNetClient->sSendSize=DEFAULT_SENDSIZE;
  423.    if(!lpNetClient->sRecvSize)
  424.         lpNetClient->sRecvSize=DEFAULT_SENDSIZE;
  425.  
  426.    lpNetClient->sErrorNumber=0;
  427.  
  428.    DEBUGNETC((LPSTR)"VBM_CREATED Marker #7.5");
  429.  
  430.        // Use the local host name if nothing was loaded
  431.    iError = gethostname((LPSTR)szLocalHostName,
  432.                           sizeof(szLocalHostName));
  433.  
  434.    DEBUGNETC((LPSTR)"VBM_CREATED Marker #8");
  435.  
  436.        // The local host name wasn't returned!
  437.    if(iError==SOCKET_ERROR)
  438.    {   // Something REAL bad happend! Abort!
  439.  
  440.     DEBUGNETC((LPSTR)"VBM_CREATED ERROR: Couldn't retrieve local host's name!");
  441.  
  442.     return(NetClientError( hCtl, WSAGetLastError()));
  443.    }
  444.  
  445.    lpNetClient->sErrorNumber=0;
  446.  
  447.    DEBUGNETC((LPSTR)"VBM_CREATED Marker #10");
  448.  
  449.    lpheHost = gethostbyname((LPSTR)szLocalHostName);
  450.  
  451.         // The local host name MUST be valid!
  452.    if(!lpheHost)
  453.    {   // This SHOULD have worked!!!
  454.  
  455.     DEBUGNETC((LPSTR)"VBM_CREATED: NULL returned by gethostbyname()");
  456.  
  457.     return(NetClientError( hCtl, WSAGetLastError()));
  458.    }
  459.  
  460.    DEBUGNETC((LPSTR)"VBM_CREATED gethostbyname() returned a HOSTENT pointer");
  461.  
  462.        // Create a new HostName
  463.    mTemp=AddMole(lpheHost->h_name);
  464.    lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  465.    lpNetClient->mHostName=mTemp;
  466.  
  467.        // Create a new HostAddr
  468.    mTemp=AddMole(inet_ntoa(*(struct in_addr FAR *)(lpheHost->h_addr)));
  469.    lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  470.    lpNetClient->mHostAddr=mTemp;
  471.  
  472.        // Save the internet address for later (Connect)
  473.    lpNetClient->saHost.sin_addr=*(struct in_addr FAR *)lpheHost->h_addr;
  474.  
  475.      // Rebuild the HostAliasList property array
  476.    lppTemp=lpheHost->h_aliases;
  477.    iCounter=0;
  478.    if(lppTemp!=NULL)
  479.    {
  480.     while(*lppTemp!=NULL)
  481.     {
  482.      mTemp=AddMole(*lppTemp);
  483.      lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  484.      if(!mTemp) break;
  485.      lpNetClient->htHostAliasList.mHost[iCounter]=mTemp;
  486.      iCounter++;
  487.      *lppTemp++;
  488.     }
  489.    }
  490.    lpNetClient->htHostAliasList.iHostCount=iCounter;
  491.  
  492.        // Rebuild the HostAddressList property array
  493.    lppTemp=lpheHost->h_addr_list;
  494.    iCounter=0;
  495.    if(lppTemp!=NULL)
  496.    {
  497.     while(*lppTemp!=NULL)
  498.     {
  499.      lpTemp=inet_ntoa(*(struct in_addr FAR *)(*lppTemp));
  500.      if(!lpTemp) break;
  501.      mTemp=AddMole(lpTemp);
  502.      lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  503.      if(!mTemp) break;
  504.      lpNetClient->htHostAddressList.mHost[iCounter]=mTemp;
  505.      iCounter++;
  506.      *lppTemp++;
  507.     }
  508.    }
  509.    lpNetClient->htHostAddressList.iHostCount=iCounter;
  510.  
  511.    DEBUGNETC((LPSTR)"VBM_CREATE End - 1");
  512.  
  513.    return(ERR_None);
  514.   } // VBM_CREATED
  515.  
  516.  
  517. #ifdef DESIGN_TIME
  518.     // Here is how to implement a dialog box property!
  519.   case VBM_INITPROPPOPUP:
  520.   {
  521.    switch(wParam)
  522.    {
  523.     case IPROP_NETCLIENT_ABOUT:
  524.     {
  525.      DEBUGNETC((LPSTR)"VBM_INITPROPPOPUP: About - Begin");
  526.  
  527.      if(bDialogInUse) return(NULL);
  528.      bDialogInUse = TRUE;
  529.      hDialogHwnd=CreateWindow(CLASS_ABOUTPOPUP, NULL,
  530.             WS_POPUP,
  531.             0, 0, 0, 0,
  532.             NULL, NULL,
  533.             hModDLL, NULL);
  534.      DEBUGNETC((LPSTR)"VBM_INITPROPPOPUP: About - End");
  535.      return(hDialogHwnd);
  536.     }
  537.     break;
  538.    }
  539.   }
  540.   break;
  541. #endif // DESIGN_TIME
  542.  
  543.  
  544. /**********************************************************************
  545.  ***                        SET PROPERTY                            ***
  546.  **********************************************************************/
  547.   case VBM_SETPROPERTY:
  548.   {
  549.    ERR err;
  550. #ifdef DEBUG_BUILD
  551.    char szError[128];
  552.  
  553.    wsprintf((LPSTR)szError, (LPSTR)"VBM_SETPROPERTY: #%d - Begin",
  554.              wParam);
  555.    DEBUGNETC((LPSTR)szError);
  556. #endif /* DEBUG_BUILD */
  557.  
  558.    switch(wParam)
  559.    {
  560.  
  561.     /****************** SET: RecvSize *******************/
  562.     // User is trying to reallocate the RecvBuffer
  563.     case IPROP_NETCLIENT_RECVSIZE:
  564.     {
  565.      DEBUGNETC((LPSTR)"SET: RecvSize - Begin");
  566.      if(lpNetClient->bConnect)      // Are we connected?
  567.      {
  568.         // Is the buffer empty?
  569.       if(lpNetClient->sRecvCount)
  570.       {
  571.         // Give the user a chance to resolve his ways...
  572.        err = clientFireOnRecv(hCtl);
  573.        if(err) return(err);
  574.  
  575.        // VB routines were probably called - dereference again
  576.        lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  577.         // Is it empty now?
  578.        if(lpNetClient->sRecvCount)
  579.        {
  580.         DEBUGNETC((LPSTR)"SET: RecvSize - Buffer not empty!!!");
  581.         return(ERR_None);     // Give up
  582.        }
  583.       }
  584.      }
  585.  
  586.      lpNetClient->sRecvSize = *(SHORT *)&lParam;
  587.  
  588.         // Unlock and free the old buffer
  589.      if(lpNetClient->hRecvBuffer)
  590.      {
  591.       GlobalUnlock(lpNetClient->hRecvBuffer);
  592.       GlobalFree(lpNetClient->hRecvBuffer);
  593.      }
  594.  
  595.         // Lock and load the receive buffer
  596.      lpNetClient->hRecvBuffer=GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE,
  597.                                           lpNetClient->sRecvSize);
  598.      lpNetClient->lpRecvBuffer=GlobalLock(lpNetClient->hRecvBuffer);
  599.      DEBUGNETC((LPSTR)"SET: RecvSize - End");
  600.      return(ERR_None);
  601.     } // IPROP_NETCLIENT_SENDSIZE
  602.  
  603.  
  604.     /****************** SET: SendSize *******************/
  605.     // User is trying to reallocate the SendBuffer
  606.     case IPROP_NETCLIENT_SENDSIZE:
  607.     {
  608.      DEBUGNETC((LPSTR)"SET: SendSize - Begin");
  609.      if(lpNetClient->sSendCount)
  610.      {
  611.         // Try flushing the SendBuffer to the net - might not work!
  612.       DEBUGNETC((LPSTR)"SET: SendSize - Buffer not empty! ");
  613.       netSendData(hCtl);
  614.       if(lpNetClient->sSendCount)
  615.         return(ERR_None);  // Couldn't flush it out, won't free it!
  616.      }
  617.  
  618.      lpNetClient->sSendSize = *(SHORT *)&lParam;
  619.  
  620.         // Unlock and free the old buffer
  621.      if(lpNetClient->hSendBuffer)
  622.      {
  623.       GlobalUnlock(lpNetClient->hSendBuffer);
  624.       GlobalFree(lpNetClient->hSendBuffer);
  625.      }
  626.  
  627.         // Lock and load the send buffer
  628.      lpNetClient->hSendBuffer=GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE,
  629.                                         lpNetClient->sSendSize);
  630.      lpNetClient->lpSendBuffer=GlobalLock(lpNetClient->hSendBuffer);
  631.  
  632.      DEBUGNETC((LPSTR)"SET: SendSize - End");
  633.      return(ERR_None);
  634.     } // IPROP_NETCLIENT_SENDSIZE
  635.  
  636.  
  637.     /****************** SET: HostName *******************/
  638.     // Try to set the HostName - We only allow valid ones!
  639.     // If an error happens, the appropriate Windows Sockets error is
  640.     // returned
  641.     case IPROP_NETCLIENT_HOSTNAME:
  642.     {
  643.      LPSTR lpHostName;
  644.      LPHOSTENT lpheHost;
  645.      MOLE mTemp;
  646.      LPSTR lpTemp;
  647.      LPSTR FAR *lppTemp;
  648.      int iCounter;
  649.  
  650.      DEBUGNETC((LPSTR)"SET: HostName - Begin");
  651.  
  652.        // Free any previous HostName
  653.      if(lpNetClient->mHostName)
  654.      {
  655.       mTemp = lpNetClient->mHostName;
  656.       DeleteMole(mTemp);
  657.       lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  658.       lpNetClient->mHostName = 0;
  659.      }
  660.        // Free any previous HostAddr
  661.      if(lpNetClient->mHostAddr)
  662.      {
  663.       mTemp = lpNetClient->mHostAddr;
  664.       DeleteMole(mTemp);
  665.       lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  666.       lpNetClient->mHostAddr = 0;
  667.      }
  668.  
  669.      if(!lParam)
  670.      {
  671.         // 'Twas an invalid string - tell the app
  672.       DEBUGNETC((LPSTR)"SET: HostName - End - lParam was NULL!!!!");
  673.  
  674.       return(netReturnError(VBERR_INVALIDPROPERTYVALUE, 0, NULL));
  675.      }
  676.  
  677.         // lParam points to a locked string during VBM_SETPROPERTY on a HSZ
  678.      lpHostName=*(LPSTR *)&lParam;
  679.  
  680.         // Try looking up the name
  681.      lpheHost=gethostbyname(lpHostName);
  682.  
  683.         // Is the pointer Valid? And the name?
  684.      if(lpheHost && lpheHost->h_name)
  685.      {
  686.       DEBUGNETC((LPSTR)"SET: HostName - gethostbyname() returned a HOSTENT pointer!!");
  687.  
  688.         // Create a new HostName
  689.       mTemp=AddMole(lpheHost->h_name);
  690.       if(!mTemp)
  691.       {
  692.        DEBUGNETC((LPSTR)"SET: HostName - End - AddMole() returned 0! (HostName)");
  693.        return(ERR_None);
  694.       }
  695.       lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  696.       lpNetClient->mHostName=mTemp;
  697.  
  698.         // Create a new HostAddr
  699.       mTemp=AddMole(inet_ntoa(*(struct in_addr FAR *)(lpheHost->h_addr)));
  700.       if(!mTemp)
  701.       {
  702.        mTemp = lpNetClient->mHostName;
  703.        DeleteMole(mTemp);
  704.        DEBUGNETC((LPSTR)"SET: HostName - End - AddMole() returned 0! (HostAddr)");
  705.        return(ERR_None);
  706.       }
  707.       lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  708.       lpNetClient->mHostAddr=mTemp;
  709.  
  710.         // Save the internet address for later (Connect)
  711.       lpNetClient->saHost.sin_addr=*(struct in_addr FAR *)lpheHost->h_addr;
  712.  
  713.         // Delete the HostAliasList property array
  714.       if(lpNetClient->htHostAliasList.iHostCount)
  715.       {
  716.        for(iCounter=0; (iCounter < (lpNetClient->htHostAliasList.iHostCount)) &&
  717.                        (iCounter < MAX_HOSTTABLESIZE); iCounter++)
  718.        {
  719.         mTemp = lpNetClient->htHostAliasList.mHost[iCounter];
  720.         DeleteMole(mTemp);
  721.         lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  722.         lpNetClient->htHostAliasList.mHost[iCounter] = 0;
  723.        }
  724.        lpNetClient->htHostAliasList.iHostCount=0;
  725.       }
  726.  
  727.         // Rebuild the HostAliasList property array
  728.       lppTemp=lpheHost->h_aliases;
  729.       iCounter=0;
  730.       if(lppTemp!=NULL)
  731.       {
  732.        while(*lppTemp!=NULL)
  733.        {
  734.         mTemp=AddMole(*lppTemp);
  735.         lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  736.         if(!mTemp) break;
  737.         lpNetClient->htHostAliasList.mHost[iCounter]=mTemp;
  738.         iCounter++;
  739.         *lppTemp++;
  740.        }
  741.       }
  742.       lpNetClient->htHostAliasList.iHostCount=iCounter;
  743.  
  744.         // Delete the HostAddressList property array
  745.       if(lpNetClient->htHostAddressList.iHostCount)
  746.       {
  747.        for(iCounter=0; (iCounter < (lpNetClient->htHostAddressList.iHostCount)) &&
  748.                        (iCounter < MAX_HOSTTABLESIZE); iCounter++)
  749.        {
  750.         mTemp = lpNetClient->htHostAddressList.mHost[iCounter];
  751.         DeleteMole(mTemp);
  752.         lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  753.         lpNetClient->htHostAddressList.mHost[iCounter] = 0;
  754.        }
  755.        lpNetClient->htHostAddressList.iHostCount=0;
  756.       }
  757.  
  758.         // Rebuild the HostAddressList property array
  759.       lppTemp=lpheHost->h_addr_list;
  760.       iCounter=0;
  761.       if(lppTemp!=NULL)
  762.       {
  763.        while(*lppTemp!=NULL)
  764.        {
  765.         lpTemp=inet_ntoa(*(struct in_addr FAR *)(*lppTemp));
  766.         if(!lpTemp) break;
  767.         mTemp=AddMole(lpTemp);
  768.         lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  769.         if(!mTemp) break;
  770.         lpNetClient->htHostAddressList.mHost[iCounter]=mTemp;
  771.         iCounter++;
  772.         *lppTemp++;
  773.        }
  774.       }
  775.       lpNetClient->htHostAddressList.iHostCount=iCounter;
  776.  
  777.       DEBUGNETC((LPSTR)"SET: HostName - End - 1");
  778.  
  779.       return(ERR_None);
  780.      }
  781.      else
  782.      {
  783.       DEBUGNETC((LPSTR)"SET: HostName - End - NULL returned by gethostbyname() ");
  784.  
  785.       return(NetClientError( hCtl, WSAGetLastError()));
  786.      }
  787.     } // IPROP_NETCLIENT_HOSTNAME
  788.  
  789.  
  790.     /****************** SET: HostAddr *******************/
  791.     // Do a reverse name query - we only accept valid IP addresses
  792.     case IPROP_NETCLIENT_HOSTADDR:
  793.     {
  794.      LPSTR lpHostAddr;
  795.      LPHOSTENT lpheHost;
  796.      IN_ADDR inHost;
  797.      LONG lHost;
  798.      MOLE mTemp;
  799.      LPSTR lpTemp;
  800.      LPSTR FAR *lppTemp;
  801.      int iCounter;
  802.  
  803.      DEBUGNETC((LPSTR)"SET: HostAddr - Begin");
  804.  
  805.        // Free any previous HostName
  806.      if(lpNetClient->mHostName)
  807.      {
  808.       mTemp = lpNetClient->mHostName;
  809.       DeleteMole(mTemp);
  810.       lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  811.       lpNetClient->mHostName = 0;
  812.      }
  813.  
  814.        // Free any previous HostAddr
  815.      if(lpNetClient->mHostAddr)
  816.      {
  817.       mTemp = lpNetClient->mHostAddr;
  818.       DeleteMole(mTemp);
  819.       lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  820.       lpNetClient->mHostAddr = 0;
  821.      }
  822.  
  823.        // No string entered?!?!
  824.      if(!lParam)
  825.      {
  826.       DEBUGNETC((LPSTR)"SET: HostAddr - End - lParam was NULL!");
  827.  
  828.       return(netReturnError(VBERR_INVALIDPROPERTYVALUE, 0, NULL ));
  829.      }
  830.  
  831.      lpHostAddr=*(LPSTR *)&lParam;
  832.      DEBUGNETC((LPSTR)lpHostAddr);
  833.  
  834.         // Change string to a long (really an in_addr)
  835.      lHost=inet_addr(lpHostAddr);
  836.      if(lHost==INADDR_NONE)
  837.      {
  838.       DEBUGNETC((LPSTR)"SET: HostAddr - End - Bad Host address format");
  839.       return(netReturnError( WSAERR_BadHostAddr, WSAERR_BadHostAddr, NULL ));
  840.      }
  841.  
  842.         // Assign the in_addr to be the return from inet_addr()
  843.      inHost.s_addr=(unsigned)lHost;
  844.      lpNetClient->saHost.sin_addr=inHost;
  845.  
  846.         // Query the database
  847.      lpheHost=gethostbyaddr((LPSTR)&lHost, 4, PF_INET);
  848.  
  849.         // Is the pointer Valid? And the name?
  850.      if(lpheHost && lpheHost->h_name)
  851.      {
  852.       DEBUGNETC((LPSTR)"SET: HostAddr - gethostbyaddr() returned a HOSTENT pointer!!");
  853.  
  854.         // Create a new HostName
  855.       mTemp=AddMole(lpheHost->h_name);
  856.       lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  857.       if(!mTemp)
  858.       {
  859.        DEBUGNETC((LPSTR)"SET: HostAddr - End - AddMole() -1- failed!");
  860.        return(ERR_None);
  861.       }
  862.       lpNetClient->mHostName=mTemp;
  863.  
  864.         // Create a new HostAddr
  865.       mTemp=AddMole(inet_ntoa(*(struct in_addr FAR *)(lpheHost->h_addr)));
  866.       lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  867.       if(!mTemp)
  868.       {
  869.         // If one fails, destroy the other
  870.        DEBUGNETC((LPSTR)"SET: HostAddr - End - AddMole() -2- failed!");
  871.        if(lpNetClient->mHostName)
  872.        {
  873.         mTemp = lpNetClient->mHostName;
  874.         DeleteMole(mTemp);
  875.         lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  876.         lpNetClient->mHostName = 0;
  877.        }
  878.        return(ERR_None);
  879.       }
  880.       lpNetClient->mHostAddr=mTemp;
  881.  
  882.         // Save the internet address for later (Connect)
  883.       lpNetClient->saHost.sin_addr=*(struct in_addr FAR *)lpheHost->h_addr;
  884.  
  885.         // Delete the HostAliasList property array
  886.       if(lpNetClient->htHostAliasList.iHostCount)
  887.       {
  888.        for(iCounter=0; (iCounter < (lpNetClient->htHostAliasList.iHostCount)) &&
  889.                        (iCounter < MAX_HOSTTABLESIZE); iCounter++)
  890.        {
  891.         mTemp = lpNetClient->htHostAliasList.mHost[iCounter];
  892.         DeleteMole(mTemp);
  893.         lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  894.         lpNetClient->htHostAliasList.mHost[iCounter] = 0;
  895.        }
  896.        lpNetClient->htHostAliasList.iHostCount=0;
  897.       }
  898.  
  899.         // Rebuild the HostAliasList property array
  900.       lppTemp=lpheHost->h_aliases;
  901.       iCounter=0;
  902.       if(lppTemp!=NULL)
  903.       {
  904.        while(*lppTemp!=NULL)
  905.        {
  906.         mTemp=AddMole(*lppTemp);
  907.         lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  908.         if(!mTemp) break;
  909.         lpNetClient->htHostAliasList.mHost[iCounter]=mTemp;
  910.         iCounter++;
  911.         *lppTemp++;
  912.        }
  913.       }
  914.       lpNetClient->htHostAliasList.iHostCount=iCounter;
  915.  
  916.         // Delete the HostAddressList property array
  917.       if(lpNetClient->htHostAddressList.iHostCount)
  918.       {
  919.        for(iCounter=0; (iCounter < (lpNetClient->htHostAddressList.iHostCount)) &&
  920.                        (iCounter < MAX_HOSTTABLESIZE); iCounter++)
  921.        {
  922.         mTemp = lpNetClient->htHostAddressList.mHost[iCounter];
  923.         DeleteMole(mTemp);
  924.         lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  925.         lpNetClient->htHostAddressList.mHost[iCounter]=0;
  926.        }
  927.        lpNetClient->htHostAddressList.iHostCount=0;
  928.       }
  929.  
  930.         // Rebuild the HostAddressList property array
  931.       lppTemp=lpheHost->h_addr_list;
  932.       iCounter=0;
  933.       if(lppTemp!=NULL)
  934.       {
  935.        while(*lppTemp!=NULL)
  936.        {
  937.         lpTemp=inet_ntoa(*(struct in_addr FAR *)(*lppTemp));
  938.         if(!lpTemp) break;
  939.         mTemp=AddMole(lpTemp);
  940.         lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  941.         if(!mTemp) break;
  942.         lpNetClient->htHostAddressList.mHost[iCounter]=mTemp;
  943.         iCounter++;
  944.         *lppTemp++;
  945.        }
  946.       }
  947.       lpNetClient->htHostAddressList.iHostCount=iCounter;
  948.  
  949.       DEBUGNETC((LPSTR)"SET: HostAddr - End - 1");
  950.  
  951.       return(ERR_None);
  952.      }
  953.      else
  954.      {
  955.       DEBUGNETC((LPSTR)"SET: HostAddr - End - NULL returned by gethostbyname() ");
  956.  
  957.       return(NetClientError( hCtl, WSAGetLastError()));
  958.      }
  959.     } // IPROP_NETCLIENT_HOSTADDR
  960.  
  961.  
  962.     /****************** SET: LineDelimiter **************/
  963.     // Setting the Line terminator
  964.     case IPROP_NETCLIENT_LINEDELIMITER:
  965.     {
  966.      char szBuffer[256];
  967.      HSZ  hszTemp;
  968.      LPSTR lpRaw, lpDelim;
  969.  
  970.      DEBUGNETC((LPSTR)"SET: LineDelimiter - Begin");
  971.          // Set the RawLineDelimiter appropriately
  972.      lpDelim=*(LPSTR *)&lParam;
  973.      lpRaw=(LPSTR)szBuffer;
  974.      while(*lpDelim)
  975.      {
  976.       if((*lpDelim=='\\')&&*(lpDelim+1))
  977.       {
  978.        lpDelim++;
  979.        switch(*lpDelim)
  980.        {                  // No, these aren't needed.. but they sure are
  981.         case 'n':         // nice for C addicts. You can fill the
  982.         *lpRaw++='\n';    // LineDelimiter property with "\r\n" for example.
  983.         lpDelim++;
  984.         break;
  985.  
  986.         case 't':
  987.         *lpRaw++='\t';
  988.         lpDelim++;
  989.         break;
  990.  
  991.         case 'r':
  992.         *lpRaw++='\r';
  993.         lpDelim++;
  994.         break;
  995.  
  996.         default:
  997.         *lpRaw++=*lpDelim++;
  998.         break;
  999.        }
  1000.       }
  1001.       else *lpRaw++=*lpDelim++;
  1002.      }
  1003.      *lpRaw='\0';
  1004.  
  1005.      if(lpNetClient->hszRawLineDelimiter)
  1006.             VBDestroyHsz(lpNetClient->hszRawLineDelimiter);
  1007.  
  1008.      hszTemp=VBCreateHsz((_segment)hCtl, (LPSTR)szBuffer);
  1009.      lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  1010.      lpNetClient->hszRawLineDelimiter=hszTemp;
  1011.  
  1012.      DEBUGNETC((LPSTR)"SET: LineDelimiter - End");
  1013.      return(ERR_None);
  1014.     } // IPROP_NETCLIENT_LINEDELIMITER
  1015.  
  1016.  
  1017.     /****************** SET: RecvLine *******************/
  1018.     // Can't set!!!
  1019.     case IPROP_NETCLIENT_RECVLINE:
  1020.         return(netReturnError(VBERR_READONLY, 0, (LPSTR)"RecvLine"));
  1021.  
  1022.  
  1023.     /****************** SET: RecvBlock ******************/
  1024.     // Can't set!!!
  1025.     case IPROP_NETCLIENT_RECVBLOCK:
  1026.         return(netReturnError(VBERR_READONLY, 0, (LPSTR)"RecvBlock"));
  1027.  
  1028.  
  1029.     /****************** SET: RecvCount ******************/
  1030.     // Can't set!!!
  1031.     case IPROP_NETCLIENT_RECVCOUNT:
  1032.         return(netReturnError(VBERR_READONLY, 0, (LPSTR)"RecvCount"));
  1033.  
  1034.  
  1035.     /****************** SET: SendCount ******************/
  1036.     // Can't set!!!
  1037.     case IPROP_NETCLIENT_SENDCOUNT:
  1038.         return(netReturnError(VBERR_READONLY, 0, (LPSTR)"RecvLine"));
  1039.  
  1040.  
  1041.     /****************** SET: ErrorMessage ****************/
  1042.     // Can't set!!!
  1043.     case IPROP_NETCLIENT_ERRORMESSAGE:
  1044.         return(netReturnError(VBERR_READONLY, 0, (LPSTR)"ErrorMessage"));
  1045.  
  1046.  
  1047.     /****************** SET: Version ********************/
  1048.     // Can't set!!!
  1049.     case IPROP_NETCLIENT_VERSION:
  1050.         return(netReturnError(VBERR_READONLY, 0, (LPSTR)"Version"));
  1051.  
  1052.  
  1053.     /****************** SET: HostAliasList **************/
  1054.     // Can't set!!!
  1055.     case IPROP_NETCLIENT_HOSTALIASLIST:
  1056.         return(netReturnError(VBERR_READONLY, 0, (LPSTR)"HostAliasList"));
  1057.  
  1058.  
  1059.     /****************** SET: HostAliasCount *************/
  1060.     // Can't set!!!
  1061.     case IPROP_NETCLIENT_HOSTALIASCOUNT:
  1062.         return(netReturnError(VBERR_READONLY, 0, (LPSTR)"HostAliasCount"));
  1063.  
  1064.  
  1065.     /****************** SET: HostAddressList ************/
  1066.     // Can't set!!!
  1067.     case IPROP_NETCLIENT_HOSTADDRESSLIST:
  1068.         return(netReturnError(VBERR_READONLY, 0, (LPSTR)"HostAddressList"));
  1069.  
  1070.  
  1071.     /****************** SET: HostAddressCount ************/
  1072.     // Can't set!!!
  1073.     case IPROP_NETCLIENT_HOSTADDRESSCNT:
  1074.         return(netReturnError(VBERR_READONLY, 0, (LPSTR)"HostAddressCount"));
  1075.  
  1076.  
  1077.     /****************** SET: LocalPort ******************/
  1078.     // Only set if we aren't connected
  1079.     case IPROP_NETCLIENT_LOCALPORT:
  1080.     {
  1081.      DEBUGNETC((LPSTR)"SET: LocalPort - Begin");
  1082.      if(!lpNetClient->bConnect)
  1083.         lpNetClient->sLocalPort=*(SHORT *)&lParam;
  1084.      DEBUGNETC((LPSTR)"SET: LocalPort - Begin");
  1085.      return(ERR_None);
  1086.     } // IPROP_NETCLIENT_LOCALPORT
  1087.  
  1088.  
  1089.     /****************** SET: RemotePort *****************/
  1090.     // Only set if we aren't connected
  1091.     case IPROP_NETCLIENT_REMOTEPORT:
  1092.     {
  1093.      DEBUGNETC((LPSTR)"SET: RemotePort - Begin");
  1094.      if(!lpNetClient->bConnect)
  1095.         lpNetClient->sRemotePort=*(SHORT *)&lParam;
  1096.      DEBUGNETC((LPSTR)"SET: RemotePort - End");
  1097.      return(ERR_None);
  1098.     } // IPROP_NETCLIENT_REMOTEPORT
  1099.  
  1100.  
  1101.     /****************** SET: LocalService ***************/
  1102.     // Handle Setting of LocalService
  1103.     case IPROP_NETCLIENT_LOCALSERVICE:
  1104.     {
  1105.      LPSTR lpLocalService;
  1106.      LPSERVENT lpseServEnt;
  1107.  
  1108.      DEBUGNETC((LPSTR)"SET: LocalService - Begin");
  1109.      if(!lParam)
  1110.      {
  1111.       lpNetClient->sLocalPort = 0;
  1112.       return(netReturnError( VBERR_INVALIDPROPERTYVALUE, 0, NULL ));
  1113.      }
  1114.  
  1115.      if(!lpNetClient->bConnect)
  1116.      {
  1117.       lpLocalService=*(LPSTR *)&lParam;
  1118.  
  1119.         // Get service by name, but don't do families... yet?
  1120.       lpseServEnt = getservbyname( lpLocalService, NULL);
  1121.  
  1122.       if(lpseServEnt)
  1123.       {
  1124.         // Copy out the port number
  1125.        lpNetClient->sLocalPort = ntohs(lpseServEnt->s_port);
  1126.       }
  1127.       else
  1128.       {
  1129.        lpNetClient->sLocalPort = 0;
  1130.        DEBUGNETC((LPSTR)"SET: LocalService - getservbyname() returned NULL!");
  1131.        return(NetClientError( hCtl, WSAGetLastError()));
  1132.       }
  1133.      }
  1134.      DEBUGNETC((LPSTR)"SET: LocalService - End");
  1135.      return(ERR_None);
  1136.     } // IPROP_NETCLIENT_LOCALSERVICE
  1137.  
  1138.  
  1139.     /****************** SET: RemoteService **************/
  1140.     // Handle Setting of RemoteService
  1141.     case IPROP_NETCLIENT_REMOTESERVICE:
  1142.     {
  1143.      LPSTR lpRemoteService;
  1144.      LPSERVENT lpseServEnt;
  1145.  
  1146.      DEBUGNETC((LPSTR)"SET: RemoteService - Begin");
  1147.      if(!lParam)
  1148.      {
  1149.       lpNetClient->sRemotePort = 0;
  1150.       return(netReturnError( VBERR_INVALIDPROPERTYVALUE, 0, NULL ));
  1151.      }
  1152.  
  1153.      if(!lpNetClient->bConnect)
  1154.      {
  1155.       lpRemoteService=*(LPSTR *)&lParam;
  1156.  
  1157.         // Get service by name, but don't do families... yet?
  1158.       lpseServEnt = getservbyname( lpRemoteService, NULL);
  1159.  
  1160.       if(lpseServEnt)
  1161.       {
  1162.         // Copy out the port number
  1163.        lpNetClient->sRemotePort = ntohs(lpseServEnt->s_port);
  1164.       }
  1165.       else
  1166.       {
  1167.        lpNetClient->sRemotePort = 0;
  1168.        DEBUGNETC((LPSTR)"SET: RemoteService - getservbyname() returned NULL!");
  1169.        return(NetClientError( hCtl, WSAGetLastError()));
  1170.       }
  1171.      }
  1172.  
  1173.      DEBUGNETC((LPSTR)"SET: RemoteService - End");
  1174.      return(ERR_None);
  1175.     } // IPROP_NETCLIENT_REMOTESERVICE
  1176.  
  1177.  
  1178.     /****************** SET: Connect ********************/
  1179.     // Try connecting to a remote host
  1180.     case IPROP_NETCLIENT_CONNECT:
  1181.     {
  1182.      SOCKET sSocket;
  1183.      LONG lNonBlocking = TRUE;
  1184.      SOCKADDR_IN saLocal;
  1185.      int iError;
  1186.  
  1187.      DEBUGNETC((LPSTR)"SET: Connect - Begin");
  1188.  
  1189.         // If we are alread connected, set an error condition.
  1190.      if((lpNetClient->bConnect) && *(BOOL *)&lParam)
  1191.      {
  1192.       DEBUGNETC((LPSTR)"SET: Connect - End - Already connected");
  1193.       return(netReturnError( WSAERR_AlreadyConn, WSAERR_AlreadyConn, NULL ));
  1194.      }
  1195.  
  1196.      if(!(lpNetClient->bConnect) && !*(BOOL *)&lParam)
  1197.      {
  1198.       DEBUGNETC((LPSTR)"SET: Connect - End - Pointless!");
  1199.       return(ERR_None);        // Ignore no connection close attempts
  1200.      }
  1201.  
  1202.         // Catch the connected close attempt
  1203.      if((lpNetClient->bConnect) && !*(BOOL *)&lParam)
  1204.      {
  1205.       netCloseSocket(hWnd, lpNetClient->sSocket);
  1206.       lpNetClient->bConnect=FALSE;
  1207.       lpNetClient->sSocket=(SOCKET)SOCKET_ERROR;
  1208.       DEBUGNETC((LPSTR)"SET: Connect - End - Closed connection!");
  1209.       return(ERR_None);
  1210.      }
  1211.  
  1212.         // In the odd case of a socket without connection, close the
  1213.         // old socket (like a non-responsive host, and a user tries
  1214.         // to connect again while we wait for FD_CONNECT).
  1215.      if(lpNetClient->sSocket != SOCKET_ERROR)
  1216.      {
  1217.       netCloseSocket(hWnd, lpNetClient->sSocket);
  1218.       lpNetClient->sSocket=(SOCKET)SOCKET_ERROR;
  1219.      }
  1220.  
  1221.         // Create a new socket
  1222.      sSocket = socket(PF_INET, SOCK_STREAM, 0);
  1223.  
  1224.         // Make sure it's valid
  1225.      if( sSocket==INVALID_SOCKET )
  1226.      {
  1227.       NetClientError( hCtl, WSAGetLastError());
  1228.       return(ERR_None);
  1229.      }
  1230.  
  1231.      WSAAsyncSelect(sSocket, hWnd, CM_NETACTIVITY,
  1232.                     FD_CONNECT | FD_READ | FD_WRITE | FD_CLOSE);
  1233.  
  1234.         // Save the socket for requests
  1235.      lpNetClient->sSocket=(SOCKET)sSocket;
  1236.  
  1237.          // Set the family and port
  1238.      lpNetClient->saHost.sin_family=AF_INET;
  1239.      lpNetClient->saHost.sin_port=htons(lpNetClient->sRemotePort);
  1240.  
  1241.          // Bind the socket to our local side - Un-Neccisary
  1242.      DEBUGNETC((LPSTR)"BIND: Begin");
  1243.      saLocal.sin_family=AF_INET;
  1244.      saLocal.sin_addr.s_addr=INADDR_ANY;
  1245.      saLocal.sin_port=htons(lpNetClient->sLocalPort);
  1246.  
  1247.      if(bind(sSocket, (LPSOCKADDR)&saLocal,
  1248.          sizeof(saLocal))==SOCKET_ERROR)
  1249.      {
  1250.       NetClientError( hCtl, WSAGetLastError());
  1251.       netCloseSocket( hWnd, sSocket);
  1252.       lpNetClient->sSocket=(SOCKET)SOCKET_ERROR;
  1253.       return(ERR_None);
  1254.      }
  1255.      DEBUGNETC((LPSTR)"BIND: End");   /**/
  1256.  
  1257.         // Start the connection to the remote host
  1258.      if(connect(sSocket, (LPSOCKADDR)&(lpNetClient->saHost),
  1259.              sizeof(lpNetClient->saHost)) == SOCKET_ERROR)
  1260.      {
  1261.         // Make sure the error we are getting is the WouldBlock warning...
  1262.       iError = WSAGetLastError();
  1263.       if(iError == WSAEWOULDBLOCK)
  1264.       {
  1265.        DEBUGNETC((LPSTR)"SET: Connect - End - All ok");
  1266.        return(ERR_None);   // Alright!
  1267.       }
  1268.  
  1269.       netCloseSocket(hWnd, sSocket);
  1270.       lpNetClient->sSocket=(SOCKET)SOCKET_ERROR;
  1271.  
  1272.         // Ah oh, something else bad went wrong... tell the user
  1273.       DEBUGNETC((LPSTR)"SET: Connect - End - connect() error");
  1274.       return(NetClientError( hCtl, iError));
  1275.      }
  1276.  
  1277.         // Must be a LocalHost connect (i.e. loopback)
  1278.      DEBUGNETC((LPSTR)"SET: Connect - End - Loopback?!?!");
  1279.  
  1280.         // Trick it!
  1281.      PostMessage(hWnd, CM_NETACTIVITY, sSocket,
  1282.                  WSAMAKESELECTREPLY(FD_CONNECT, 0));
  1283.      return(ERR_None);
  1284.     }
  1285.     break; // IPROP_NETCLIENT_CONNECT
  1286.  
  1287.  
  1288.     /****************** SET: TimeOut ********************/
  1289.     // Set the TimeOut property
  1290.     case IPROP_NETCLIENT_TIMEOUT:
  1291.     {
  1292.      DEBUGNETC((LPSTR)"SET: TimeOut - Begin");
  1293.         // If setting it to 0, mark for WM_TIMER that it shan't go on
  1294.      if(lParam==0)
  1295.      {
  1296.       lpNetClient->sTimeOut=lpNetClient->sTimeOutStore=0;
  1297.       return(ERR_None);
  1298.      }
  1299.  
  1300.         // Set the new TimeOut value
  1301.      lpNetClient->sTimeOutStore=*(SHORT *)&lParam;
  1302.  
  1303.      if(lpNetClient->sTimeOut)
  1304.      {
  1305.       lpNetClient->sTimeOut=lpNetClient->sTimeOutStore;
  1306.       return(ERR_None);
  1307.      }
  1308.  
  1309.      if(!SetTimer(hWnd, IDTIME_TIMEOUT, 1000, NULL))
  1310.      {
  1311.       return(netReturnError( WSAERR_NoTimers, WSAERR_NoTimers, 0 ));
  1312.      }
  1313.  
  1314.      lpNetClient->sTimeOut=lpNetClient->sTimeOutStore;
  1315.  
  1316.      DEBUGNETC((LPSTR)"SET: TimeOut - End");
  1317.      return(ERR_None);
  1318.     }
  1319.     break; // IPROP_NETCLIENT_TIMEOUT
  1320.  
  1321.  
  1322.     /****************** SET: Line ***********************/
  1323.     /****************** SET: SendLine *******************/
  1324.     // Send a line
  1325.     case IPROP_NETCLIENT_LINE:
  1326.     case IPROP_NETCLIENT_SENDLINE:
  1327.     {
  1328.      LPSTR lpLine;
  1329.      MOLE mLine;
  1330.  
  1331.      DEBUGNETC((LPSTR)"SET: SendLine - Begin");
  1332.  
  1333.      if(!lParam)
  1334.      {
  1335.       DEBUGNETC((LPSTR)"SET: SendLine - No lParam!");
  1336.       return(netReturnError( VBERR_INVALIDPROPERTYVALUE, 0, NULL ));
  1337.      }
  1338.  
  1339.      lpLine=*(LPSTR *)&lParam;
  1340.  
  1341.         // Put some data in the SendLine property
  1342.      DEBUGNETC((LPSTR)"SET: SendLine - Marker #1");
  1343.  
  1344.         // Repackage the HSZ string as a HLSTR
  1345.      mLine = CreateMole(lpLine, (USHORT)lstrlen(lpLine));
  1346.  
  1347.      if(!mLine)
  1348.      {
  1349.       DEBUGNETC((LPSTR)"SET: SendLine - End - CreateMole() returned 0!");
  1350.       return(netReturnError(VBERR_OUTOFMEMORY, 0, NULL));
  1351.      }
  1352.  
  1353.         // Send the string as a block
  1354.      DEBUGNETC((LPSTR)"SET: SendLine - calling putSendData()");
  1355.  
  1356.      if(putSendData(hCtl, mLine) == SOCKET_ERROR)
  1357.      {
  1358.       DeleteMole(mLine);
  1359.       return(netReturnError(WSAERR_SendOverFlow, WSAERR_SendOverFlow, NULL ));
  1360.      }
  1361.  
  1362.         // Unlock and destroy the strings
  1363.      DeleteMole(mLine);
  1364.      DEBUGNETC((LPSTR)"SET: SendLine - End");
  1365.      return(ERR_None);
  1366.     } // IPROP_NETCLIENT_SENDLINE/IPROP_NETCLIENT_LINE
  1367.  
  1368.  
  1369.     /****************** SET: Block **********************/
  1370.     /****************** SET: SendBlock ******************/
  1371.     // Send a block
  1372.     case IPROP_NETCLIENT_BLOCK:
  1373.     case IPROP_NETCLIENT_SENDBLOCK:
  1374.     {
  1375.      HLSTR hlLine;
  1376.  
  1377.      DEBUGNETC((LPSTR)"SET: SendBlock - Begin");
  1378.  
  1379.         // We MUST copy the HLSTR to another one (that we own)
  1380.         //  before we can even USE IT! Seems that HLSTR must be
  1381.         //  stored in VB's local address space.
  1382.      hlLine=VBCreateHlstr(NULL, 0);
  1383.      VBSetHlstr((HLSTR FAR *)&hlLine, (LPVOID)(*(HLSTR *)&lParam), 1);
  1384.  
  1385.         // Send the data passed as a block
  1386.      putSendData(hCtl, (MOLE)hlLine);
  1387.  
  1388.      VBDestroyHlstr(hlLine);
  1389.  
  1390.      DEBUGNETC((LPSTR)"SET: SendBlock - End");
  1391.      return(ERR_None);
  1392.     } // IPROP_NETCLIENT_SENDBLOCK/IPROP_NETCLIENT_BLOCK
  1393.  
  1394.  
  1395.     /****************** SET: Socket *********************/
  1396.     // Allow the user to set the socket parameter
  1397.     case IPROP_NETCLIENT_SOCKET:
  1398.     {  //"xxx.xxx.xxx.xxx"
  1399.      char szHostAddr[16];
  1400.      LPSTR lpHostAddr;
  1401.      SOCKET sSocket = *(SOCKET *)&lParam;
  1402.      SOCKADDR_IN saHost;
  1403.      int iSize = sizeof(saHost);
  1404.  
  1405.      DEBUGNETC((LPSTR)"SET: Socket - Start");
  1406.  
  1407.      if((sSocket!=0) && (sSocket!=SOCKET_ERROR))
  1408.      {
  1409.       if((lpNetClient->sSocket != 0) &&
  1410.          (lpNetClient->sSocket != SOCKET_ERROR))
  1411.       {
  1412.        netCloseSocket(hWnd, lpNetClient->sSocket);
  1413.       }
  1414.       lpNetClient->sSocket=sSocket;
  1415.  
  1416.       if(getpeername(sSocket, (LPSOCKADDR)&saHost, (LPINT)&iSize) ==
  1417.          SOCKET_ERROR)
  1418.         return(NetClientError(hCtl, WSAGetLastError()));
  1419.  
  1420.       DEBUGNETC((LPSTR)"SET: Socket - getpeername() was successful");
  1421.  
  1422.       lpHostAddr=inet_ntoa(saHost.sin_addr);
  1423.  
  1424.       if(lpHostAddr == NULL)
  1425.         return(NetClientError(hCtl, WSAGetLastError()));
  1426.  
  1427.       DEBUGNETC((LPSTR)"SET: Socket - inet_ntoa() was successful");
  1428.  
  1429.       if(lstrlen(lpHostAddr) < 16)
  1430.        lstrcpy((LPSTR)szHostAddr, lpHostAddr);
  1431.       else
  1432.       {
  1433.        DEBUGNETC((LPSTR)"SET: Socket - host address is more than 15 chars?!?!");
  1434.        return(ERR_None);
  1435.       }
  1436.  
  1437.       lpNetClient->bConnect = FALSE;
  1438.  
  1439.       VBSetControlProperty(hCtl, IPROP_NETCLIENT_HOSTADDR, (LONG)(LPSTR)szHostAddr);
  1440.  
  1441.       lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  1442.  
  1443.       DEBUGNETC((LPSTR)"SET: Socket - set HostAddr.. properties");
  1444.  
  1445.       lpNetClient->sRemotePort=(SHORT)htons(saHost.sin_port);
  1446.  
  1447.       if(getsockname(sSocket, (LPSOCKADDR)&saHost, (LPINT)&iSize) ==
  1448.          SOCKET_ERROR)
  1449.         return(NetClientError(hCtl, WSAGetLastError()));
  1450.  
  1451.       DEBUGNETC((LPSTR)"SET: Socket - getsockname() was successful");
  1452.  
  1453.       lpNetClient->sLocalPort=(SHORT)htons(saHost.sin_port);
  1454.  
  1455.       netConnect(hCtl, sSocket);
  1456.  
  1457.       DEBUGNETC((LPSTR)"SET: Socket - End");
  1458.       return(ERR_None);
  1459.      }
  1460.      else
  1461.      {  // User obviously wants to close the connection, if any.
  1462.       return(VBSetControlProperty(hCtl, IPROP_NETCLIENT_CONNECT, (LONG)FALSE));
  1463.      }
  1464.     }
  1465.     break; // IPROP_NETCLIENT_SOCKET
  1466.  
  1467.  
  1468.     /****************** SET: Debug **********************/
  1469.     // Set SO_DEBUG
  1470.     case IPROP_NETCLIENT_DEBUG:
  1471.     {
  1472.      BOOL fDebug = *(BOOL *)&lParam;
  1473.  
  1474.      DEBUGNETC((LPSTR)"SET: Debug - Begin");
  1475.  
  1476.      if((lpNetClient->sSocket != 0) &&
  1477.         (lpNetClient->sSocket != SOCKET_ERROR))
  1478.      {
  1479.       if(setsockopt(lpNetClient->sSocket, SOL_SOCKET, SO_DEBUG,
  1480.                     (LPSTR)&fDebug, sizeof(fDebug))
  1481.                != SOCKET_ERROR)
  1482.       {
  1483.        DEBUGNETC((LPSTR)"SET: Debug - End - Ok");
  1484.        return(ERR_None);
  1485.       }
  1486.       else return(NetClientError(hCtl, WSAGetLastError()));
  1487.      }
  1488.      return(netReturnError(WSAERR_NotConn, WSAERR_NotConn, NULL));
  1489.     }
  1490.     break; // IPROP_NETCLIENT_DEBUG
  1491.  
  1492.  
  1493.     /****************** SET: Host ***********************/
  1494.     // Try HostAddr and then HostName
  1495.     case IPROP_NETCLIENT_HOST:
  1496.     {
  1497.      ERR err;
  1498.  
  1499.      DEBUGNETC((LPSTR)"SET: Host - Begin");
  1500.  
  1501.      lpNetClient->sErrorNumber = 0;
  1502.      err=VBSetControlProperty(hCtl, IPROP_NETCLIENT_HOSTNAME, lParam);
  1503.      lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  1504.      if(lpNetClient)
  1505.      {
  1506.       if(!(lpNetClient->mHostName))
  1507.       {
  1508.        DEBUGNETC((LPSTR)"SET: Host - HostName failed... Trying HostAddr");
  1509.  
  1510.        err=VBSetControlProperty(hCtl, IPROP_NETCLIENT_HOSTADDR, lParam);
  1511.       }
  1512.       else
  1513.       {
  1514.        DEBUGNETC((LPSTR)"SET: Host - HostName was successful!");
  1515.       }
  1516.      }
  1517.  
  1518.      DEBUGNETC((LPSTR)"SET: Host - End");
  1519.      return(err);
  1520.     }
  1521.     break; // IPROP_NETCLIENT_HOST
  1522.  
  1523.    }
  1524.   }
  1525.   break;
  1526.  
  1527.  
  1528. /**********************************************************************
  1529.  ***                        GET PROPERTY                            ***
  1530.  **********************************************************************/
  1531.   case VBM_GETPROPERTY:
  1532.   {
  1533. #ifdef DEBUG_BUILD
  1534.    char szError[128];
  1535.  
  1536.    wsprintf((LPSTR)szError, (LPSTR)"VBM_GETPROPERTY: #%d: Begin",
  1537.             wParam);
  1538.    DEBUGNETC((LPSTR)szError);
  1539. #endif /* DEBUG_BUILD */
  1540.  
  1541.    switch(wParam)
  1542.    {
  1543.  
  1544.     /****************** GET: Line     *******************/
  1545.     /****************** GET: RecvLine *******************/
  1546.     // Receive a line
  1547.     case IPROP_NETCLIENT_LINE:
  1548.     case IPROP_NETCLIENT_RECVLINE:
  1549.     {
  1550.      DEBUGNETC((LPSTR)"GET: RecvLine - Start");
  1551.  
  1552.      *(*(LPHSZ *)&lParam) = getRecvLine(hCtl);
  1553.  
  1554.      DEBUGNETC((LPSTR)"GET: RecvLine - End");
  1555.      return(ERR_None);
  1556.     } // IPROP_NETCLIENT_LINE/IPROP_NETCLIENT_RECVLINE
  1557.  
  1558.  
  1559.     /****************** GET: Block **********************/
  1560.     /****************** GET: RecvBlock ******************/
  1561.     // Receive a block
  1562.     case IPROP_NETCLIENT_BLOCK:
  1563.     case IPROP_NETCLIENT_RECVBLOCK:
  1564.     {
  1565.      HLSTR hlStr;
  1566.  
  1567.      DEBUGNETC((LPSTR)"GET: RecvBlock - Start");
  1568.  
  1569.      hlStr = getRecvData(hCtl);
  1570.      if(hlStr==NULL)
  1571.      {
  1572.       hlStr=VBCreateHlstr(NULL, 0);
  1573.      }
  1574.      *(*(LPHLSTR *)&lParam) = hlStr;
  1575.  
  1576.      DEBUGNETC((LPSTR)"GET: RecvBlock - End");
  1577.      return(ERR_None);
  1578.     } // IPROP_NETCLIENT_BLOCK/IPROP_NETCLIENT_RECVBLOCK
  1579.  
  1580.  
  1581.     /****************** GET: SendLine *******************/
  1582.     // Can't get!!!
  1583.     case IPROP_NETCLIENT_SENDLINE:
  1584.         return(netReturnError(VBERR_WRITEONLY, 0, (LPSTR)"SendLine"));
  1585.  
  1586.  
  1587.     /****************** GET: SendBlock ******************/
  1588.     // Can't get!!!
  1589.     case IPROP_NETCLIENT_SENDBLOCK:
  1590.         return(netReturnError(VBERR_WRITEONLY, 0, (LPSTR)"SendBlock"));
  1591.  
  1592.  
  1593.     /****************** GET: LocalService ***************/
  1594.     case IPROP_NETCLIENT_LOCALSERVICE:
  1595.     {
  1596.      HSZ hszTemp;
  1597.      LPSERVENT lpseServEnt;
  1598.      BOOL bClear = FALSE;
  1599.  
  1600.      DEBUGNETC((LPSTR)"GET: LocalService - Begin");
  1601.  
  1602.      lpseServEnt = getservbyport( htons(lpNetClient->sLocalPort), NULL);
  1603.      if(lpseServEnt)
  1604.      {
  1605.       if(lpseServEnt->s_name)
  1606.       {
  1607.        hszTemp = VBCreateHsz((_segment)hCtl, lpseServEnt->s_name);
  1608.       }
  1609.       else bClear = TRUE;
  1610.      }
  1611.      else
  1612.      {
  1613.       bClear = TRUE;
  1614.       NetClientError(hCtl, WSAGetLastError());
  1615.      }
  1616.  
  1617.      if(bClear)
  1618.      {
  1619.       char cChar = '\0';
  1620.  
  1621.       hszTemp = VBCreateHsz((_segment)hCtl, (LPSTR)&cChar);
  1622.      }
  1623.  
  1624.      *(*(LPHSZ *)&lParam) = hszTemp;
  1625.  
  1626.      DEBUGNETC((LPSTR)"GET: LocalService - End");
  1627.      return(ERR_None);
  1628.     } // IPROP_NETCLIENT_LOCALSERVICE
  1629.  
  1630.  
  1631.     /****************** GET: RemoteService **************/
  1632.     case IPROP_NETCLIENT_REMOTESERVICE:
  1633.     {
  1634.      HSZ hszTemp;
  1635.      LPSERVENT lpseServEnt;
  1636.      BOOL bClear = FALSE;
  1637.  
  1638.      DEBUGNETC((LPSTR)"GET: RemoteService - Begin");
  1639.      lpseServEnt = getservbyport( htons(lpNetClient->sRemotePort), NULL);
  1640.      if(lpseServEnt)
  1641.      {
  1642.       if(lpseServEnt->s_name)
  1643.       {
  1644.        hszTemp = VBCreateHsz((_segment)hCtl, lpseServEnt->s_name);
  1645.       }
  1646.       else bClear = TRUE;
  1647.      }
  1648.      else
  1649.      {
  1650.       bClear = TRUE;
  1651.       NetClientError(hCtl, WSAGetLastError());
  1652.      }
  1653.  
  1654.      if(bClear)
  1655.      {
  1656.       char cChar = '\0';
  1657.  
  1658.       hszTemp = VBCreateHsz((_segment)hCtl, (LPSTR)&cChar);
  1659.      }
  1660.  
  1661.      *(*(LPHSZ *)&lParam) = hszTemp;
  1662.  
  1663.      DEBUGNETC((LPSTR)"GET: RemoteService - End");
  1664.      return(ERR_None);
  1665.     } // IPROP_NETCLIENT_REMOTESERVICE
  1666.  
  1667.  
  1668.     /****************** GET: RecvCount ******************/
  1669.     // Calculate the current RecvBuffer size
  1670.     case IPROP_NETCLIENT_RECVCOUNT:
  1671.     {
  1672.      DEBUGNETC((LPSTR)"GET: RecvCount - Start");
  1673.  
  1674.       *(*(SHORT FAR **)&lParam)=lpNetClient->sRecvCount;
  1675.  
  1676.      DEBUGNETC((LPSTR)"GET: RecvCount - End");
  1677.      return(ERR_None);
  1678.     } // IPROP_NETCLINET_RECVCOUNT
  1679.  
  1680.  
  1681.     /****************** GET: SendCount ******************/
  1682.     // Calculate the current SendBuffer size
  1683.     case IPROP_NETCLIENT_SENDCOUNT:
  1684.     {
  1685.       DEBUGNETC((LPSTR)"GET: SendCount - Start");
  1686.  
  1687.       *(*(SHORT FAR **)&lParam)=lpNetClient->sSendCount;
  1688.  
  1689.       DEBUGNETC((LPSTR)"GET: SendCount - End");
  1690.       return(ERR_None);
  1691.     } // IPROP_NETCLINET_RECVCOUNT
  1692.  
  1693.  
  1694.     /****************** GET: ErrorMessage ***************/
  1695.     case IPROP_NETCLIENT_ERRORMESSAGE:
  1696.     {
  1697.      char szString[256];
  1698.      HSZ  hszTemp;
  1699.      char cChar;
  1700.      int iError;
  1701.  
  1702.      DEBUGNETC((LPSTR)"GET: ErrorMessage - Begin");
  1703.  
  1704.      iError=lpNetClient->sErrorNumber;
  1705.      if(!LoadString(hModDLL, iError, (LPSTR)szString,
  1706.                 sizeof(szString)))
  1707.      {
  1708.       wsprintf((LPSTR)szString, (LPSTR)"Unknown Error #%d",
  1709.                iError);
  1710.      }
  1711.  
  1712. #ifdef DESIGN_TIME
  1713.      // MessageBeep(MB_ICONEXCLAMATION);
  1714.      DEBUGNETC((LPSTR)szString);
  1715. #endif
  1716.  
  1717.      // Set the error message text
  1718.  
  1719.      cChar='\0';
  1720.      hszTemp=VBCreateHsz((_segment)hCtl, (LPSTR)szString);
  1721.      DEBUGNETC((LPSTR)"GET: ErrorMessage - Created new error string");
  1722.      if(!hszTemp) hszTemp=VBCreateHsz((_segment)hCtl, (LPSTR)&cChar);
  1723.  
  1724.      *(*(LPHSZ *)&lParam) = hszTemp;
  1725.  
  1726.      DEBUGNETC((LPSTR)"GET: ErrorMessage - End");
  1727.      return(ERR_None);
  1728.     } // IPROP_NETCLIENT_ERRORMESSAGE
  1729.  
  1730.  
  1731.     /****************** GET: Version ********************/
  1732.     // Get NetClient version string...
  1733.     case IPROP_NETCLIENT_VERSION:
  1734.     {
  1735.      HSZ hszTemp;
  1736.      char cChar = '\0';
  1737.  
  1738.      DEBUGNETC((LPSTR)"GET: Version - Begin");
  1739.  
  1740.      hszTemp=VBCreateHsz((_segment)hCtl, (LPSTR)WSANET_VERSION_TEXT);
  1741.      if(!hszTemp) hszTemp=VBCreateHsz((_segment)hCtl, (LPSTR)&cChar);
  1742.  
  1743.      *(*(LPHSZ *)&lParam) = hszTemp;
  1744.      DEBUGNETC((LPSTR)WSANET_VERSION_TEXT);
  1745.  
  1746.      DEBUGNETC((LPSTR)"GET: Version - End");
  1747.      return(ERR_None);
  1748.     } // IPROP_NETCLIENT_VERSION
  1749.  
  1750.  
  1751.     /****************** GET: Debug **********************/
  1752.     // Get SO_DEBUG
  1753.     case IPROP_NETCLIENT_DEBUG:
  1754.     {
  1755.      BOOL fDebug;
  1756.      int iSize = sizeof(fDebug);
  1757.  
  1758.      DEBUGNETC((LPSTR)"GET: Debug - Begin");
  1759.  
  1760.      if((lpNetClient->sSocket != 0) &&
  1761.         (lpNetClient->sSocket != SOCKET_ERROR))
  1762.      {
  1763.       if(getsockopt(lpNetClient->sSocket, SOL_SOCKET, SO_DEBUG,
  1764.                     (LPSTR)&fDebug, (int FAR *)&iSize)
  1765.            != SOCKET_ERROR)
  1766.       {
  1767.        *(*(SHORT FAR **)&lParam)=(SHORT)fDebug;
  1768.        DEBUGNETC((LPSTR)"GET: Debug - End - SO_DEBUG returned");
  1769.        return(ERR_None);
  1770.       }
  1771.      }
  1772.      *(*(SHORT FAR **)&lParam)=0;
  1773.      DEBUGNETC((LPSTR)"GET: Debug - End - False returned");
  1774.      return(ERR_None);
  1775.     } // IPROP_NETCLIENT_DEBUG
  1776.  
  1777.  
  1778.     /****************** GET: Host *************************/
  1779.     // Get HostName.
  1780.     case IPROP_NETCLIENT_HOST:
  1781.     /****************** GET: HostName *******************/
  1782.     // Get HostName from its MOLE
  1783.     case IPROP_NETCLIENT_HOSTNAME:
  1784.     {
  1785.      HSZ hszTemp;
  1786.  
  1787.      DEBUGNETC((LPSTR)"GET: HostName - Begin");
  1788.  
  1789.      hszTemp = GetMoleHsz(hCtl,lpNetClient->mHostName);
  1790.      if(!hszTemp)
  1791.      {
  1792.       DEBUGNETC((LPSTR)"GET: HostName - End - Critical error!");
  1793.       return(netReturnError(VBERR_OUTOFMEMORY, 0, NULL));
  1794.      }
  1795.  
  1796.      *(*(LPHSZ *)&lParam) = hszTemp;
  1797.  
  1798.      DEBUGNETC((LPSTR)"GET: HostName - End");
  1799.      return(ERR_None);
  1800.     } // IPROP_NETCLIENT_HOSTNAME
  1801.  
  1802.  
  1803.     /****************** GET: HostAddr *******************/
  1804.     // Get HostAddr from its MOLE
  1805.     case IPROP_NETCLIENT_HOSTADDR:
  1806.     {
  1807.      HSZ hszTemp;
  1808.  
  1809.      DEBUGNETC((LPSTR)"GET: HostAddr - Begin");
  1810.  
  1811.      hszTemp = GetMoleHsz(hCtl,lpNetClient->mHostAddr);
  1812.      if(!hszTemp)
  1813.      {
  1814.       DEBUGNETC((LPSTR)"GET: HostAddr - End - Critical error!");
  1815.       return(netReturnError(VBERR_OUTOFMEMORY, 0, NULL));
  1816.      }
  1817.  
  1818.      *(*(LPHSZ *)&lParam) = hszTemp;
  1819.  
  1820.      DEBUGNETC((LPSTR)"GET: HostAddr - End");
  1821.      return(ERR_None);
  1822.     } // IPROP_NETCLIENT_HOSTADDR
  1823.  
  1824.  
  1825.     /****************** GET: HostAliasCount *************/
  1826.     // Get the current number of elements in
  1827.     //  HostAliasList
  1828.     case IPROP_NETCLIENT_HOSTALIASCOUNT:
  1829.     {
  1830.       DEBUGNETC((LPSTR)"GET: HostAliasCount - Start");
  1831.  
  1832.       *(*(SHORT FAR **)&lParam)=lpNetClient->htHostAliasList.iHostCount;
  1833.  
  1834.       DEBUGNETC((LPSTR)"GET: HostAliasCount - End");
  1835.       return(ERR_None);
  1836.     } // IPROP_NETCLINET_HOSTALIASCOUNT
  1837.  
  1838.  
  1839.     /****************** GET: HostAddressCount ***********/
  1840.     // Get the current number of elements in
  1841.     //  HostAddressList
  1842.     case IPROP_NETCLIENT_HOSTADDRESSCNT:
  1843.     {
  1844.       DEBUGNETC((LPSTR)"GET: HostAddressCount - Start");
  1845.  
  1846.       *(*(SHORT FAR **)&lParam)=lpNetClient->htHostAddressList.iHostCount;
  1847.  
  1848.       DEBUGNETC((LPSTR)"GET: HostAddressCount - End");
  1849.       return(ERR_None);
  1850.     } // IPROP_NETCLIENT_HOSTADDRESSCNT
  1851.  
  1852.  
  1853.     /****************** GET: HostAliasList() ************/
  1854.     // Get a element of HostAliasList
  1855.     case IPROP_NETCLIENT_HOSTALIASLIST:
  1856.     {
  1857.       LONG lIndex;
  1858.       MOLE mTemp;
  1859.       HSZ hszTemp;
  1860.       LPDATASTRUCT lpdsElement = (LPDATASTRUCT)lParam;
  1861.  
  1862.       DEBUGNETC((LPSTR)"GET: HostAliasList - Start");
  1863.  
  1864.       lIndex = lpdsElement->index[0].data;
  1865.       if((lIndex < 0) ||
  1866.          (lIndex > lpNetClient->htHostAliasList.iHostCount))
  1867.       {
  1868.        return(netReturnError(VBERR_BADVBINDEX, 0, NULL));
  1869.       }
  1870.  
  1871.       mTemp = lpNetClient->htHostAliasList.mHost[lIndex];
  1872.  
  1873.       hszTemp = GetMoleHsz(hCtl,mTemp);
  1874.  
  1875.       if(!hszTemp) return(netReturnError(VBERR_OUTOFMEMORY, 0, NULL));
  1876.  
  1877.       lpdsElement->data=(LONG)hszTemp;
  1878.  
  1879.       DEBUGNETC((LPSTR)"GET: HostAliasList - End");
  1880.       return(ERR_None);
  1881.     } // IPROP_NETCLINET_HOSTALIASLIST
  1882.  
  1883.  
  1884.     /****************** GET: HostAddressList() ************/
  1885.     // Get a element of HostAddressList
  1886.     case IPROP_NETCLIENT_HOSTADDRESSLIST:
  1887.     {
  1888.       LONG lIndex;
  1889.       MOLE mTemp;
  1890.       HSZ hszTemp;
  1891.       LPDATASTRUCT lpdsElement = (LPDATASTRUCT)lParam;
  1892.  
  1893.       DEBUGNETC((LPSTR)"GET: HostAddressList - Start");
  1894.  
  1895.       lIndex = lpdsElement->index[0].data;
  1896.       if((lIndex < 0) ||
  1897.          (lIndex > lpNetClient->htHostAddressList.iHostCount))
  1898.       {
  1899.        return(netReturnError(VBERR_BADVBINDEX, 0, NULL));
  1900.       }
  1901.  
  1902.       mTemp = lpNetClient->htHostAddressList.mHost[lIndex];
  1903.  
  1904.       hszTemp = GetMoleHsz(hCtl,mTemp);
  1905.  
  1906.       if(!hszTemp) return(netReturnError(VBERR_OUTOFMEMORY, 0, NULL));
  1907.  
  1908.       lpdsElement->data=(LONG)hszTemp;
  1909.  
  1910.       DEBUGNETC((LPSTR)"GET: HostAddressList - End");
  1911.       return(ERR_None);
  1912.     } // IPROP_NETCLIENT_HOSTALIASLIST
  1913.  
  1914.  
  1915.     /****************** GET: DEFAULT handler! ***********/
  1916.     default:
  1917.     {
  1918.      DEBUGNETC((LPSTR)"GET: Property not handled");
  1919.     }
  1920.     break;
  1921.    }
  1922.    DEBUGNETC((LPSTR)"VBM_GETPROPERTY: End");
  1923.   }
  1924.   break;
  1925.  
  1926.  
  1927. /**********************************************************************
  1928.  ***                        GET PROPERTY HSZ                        ***
  1929.  **********************************************************************/
  1930. #ifdef DESIGN_TIME
  1931.     // Set the About propery to display "About NetClient"
  1932.   case VBM_GETPROPERTYHSZ:
  1933.   {
  1934.    DEBUGNETC((LPSTR)"VBM_GETPROPERTYHSZ Begin");
  1935.    switch(wParam)
  1936.    {
  1937.     case IPROP_NETCLIENT_ABOUT:
  1938.     {
  1939.      DEBUGNETC((LPSTR)"GETPROPERTYHSZ: About");
  1940.      *(*(LPHSZ *)&lParam) = VBCreateHsz((_segment) hCtl, (LPSTR)STRING_ABOUTTEXT);
  1941.      return(ERR_None);
  1942.     }
  1943.  
  1944.     case IPROP_NETCLIENT_SENDBLOCK:
  1945.     case IPROP_NETCLIENT_SENDLINE:
  1946.     {
  1947.      DEBUGNETC((LPSTR)"GETPROPERTYHSZ: Send(Block/Line)");
  1948.      *(*(LPHSZ *)&lParam) = VBCreateHsz((_segment) hCtl, (LPSTR)STRING_WRITEONLY);
  1949.      return(ERR_None);
  1950.     }
  1951.    }
  1952.    DEBUGNETC((LPSTR)"VBM_GETPROPERTYHSZ End");
  1953.   }
  1954.   break;
  1955.  
  1956.  
  1957. /**********************************************************************
  1958.  ***                   CONTEXT SENSITIVE HELP                       ***
  1959.  **********************************************************************/
  1960.   case VBM_HELP:
  1961.   {
  1962. #ifdef DEBUG_BUILD
  1963.    char szError[128];
  1964.  
  1965.    DEBUGNETC((LPSTR)"VBM_HELP: Begin");
  1966.    wsprintf((LPSTR)szError, (LPSTR)"VBM_HELP: Prop. #%d",
  1967.              wParam );
  1968.    DEBUGNETC((LPSTR)szError);
  1969. #endif // DEBUG_BULD
  1970.  
  1971.    if(bHelpStdPropEvt(wParam, (LPMODEL)lParam))
  1972.         break;
  1973.    else return(DisplayHelpTopic(TOPIC_CONTROL_NETCLIENT, wParam,
  1974.                                 (LPMODEL)lParam));
  1975.    DEBUGNETC((LPSTR)"VBM_HELP: Standard handler allowed");
  1976.   }
  1977.   break;
  1978. #endif // DESIGN_TIME
  1979.  
  1980.  
  1981.     // **** The network activity message ****
  1982.   case CM_NETACTIVITY:
  1983.   {
  1984.    DEBUGNETC((LPSTR)"CM_NETACTIVITY");
  1985.  
  1986.    return(netClientAsyncProc(hCtl, hWnd, wParam, lParam));
  1987.   }
  1988.  
  1989.     // TimeOut handler.
  1990.   case WM_TIMER:
  1991.   {
  1992.    DEBUGNETC((LPSTR)"WM_TIMER: Begin");
  1993.    if(lpNetClient->sTimeOut) (lpNetClient->sTimeOut)--;
  1994.    if(lpNetClient->sTimeOut <= 0)
  1995.    {
  1996.     lpNetClient->sTimeOut=0;
  1997.     KillTimer(hWnd, wParam);
  1998.     clientFireOnTimeOut(hCtl);
  1999.    }
  2000.    DEBUGNETC((LPSTR)"WM_TIMER: End");
  2001.    return(ERR_None);
  2002.   }
  2003.   break;
  2004.  
  2005.  }
  2006.  return(VBDefControlProc(hCtl, hWnd, (USHORT)Msg, (USHORT)wParam,
  2007.         (LONG)lParam));
  2008. } /* NetClientCtlProc() */
  2009.  
  2010.  
  2011. /* LONG CALLBACK _export AboutWndProc(HWND, UINT, WPARAM, LPARAM);
  2012.     Purpose: To display a dialog for a popup window
  2013. */
  2014. LONG CALLBACK _export AboutWndProc(HWND hWnd, UINT Msg,
  2015.                                    WPARAM wParam, LPARAM lParam)
  2016. {
  2017.  switch(Msg)
  2018.  {
  2019.   case WM_DESTROY:
  2020.   {
  2021.    bDialogInUse=FALSE;
  2022.   }
  2023.   break;
  2024.  
  2025.   case WM_SHOWWINDOW:
  2026.   {
  2027.    if (wParam)
  2028.    {
  2029.     PostMessage(hWnd, CM_OPENABOUTDLG, 0, 0L);
  2030.     return(0L);
  2031.    }
  2032.   }
  2033.   break;
  2034.  
  2035.   case CM_OPENABOUTDLG:
  2036.   {
  2037.    VBDialogBoxParam(hModDLL, "AboutDlg",
  2038.                     (FARPROC)AboutDlgProc , 0L);
  2039.    return(0L);
  2040.   }
  2041.   break;
  2042.  }
  2043.  return(DefWindowProc(hWnd, Msg, wParam, lParam));
  2044. } /* AboutWndProc() */
  2045.  
  2046.  
  2047. /* BOOL CALLBACK _export AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
  2048.     Purpose: To handle the About dialog
  2049. */
  2050. BOOL CALLBACK _export AboutDlgProc(HWND hWndDlg, UINT Msg,
  2051.                                    WPARAM wParam, LPARAM lParam)
  2052. {
  2053. #ifdef USE_VCPP
  2054.  lParam = lParam;
  2055. #endif /* USE_VCPP */
  2056.  switch(Msg)
  2057.  {
  2058.   case WM_INITDIALOG:
  2059.   {
  2060.    return(TRUE);
  2061.   }
  2062.   break;
  2063.  
  2064.   case WM_COMMAND:
  2065.   {
  2066.    switch(wParam)
  2067.    {
  2068.     case IDOK:
  2069.     {
  2070.      EndDialog(hWndDlg, TRUE);
  2071.      return(TRUE);
  2072.     }
  2073.     break;
  2074.    }
  2075.   }
  2076.   break;
  2077.  }
  2078.  return(FALSE);
  2079. } /* AboutDlgProc() */
  2080.  
  2081.  
  2082. /* ERR NetClientError(HCTL hCtl, int);
  2083.     Purpose: To set a VB error level and string to any errors
  2084. */
  2085. ERR NetClientError(HCTL hCtl, int iError)
  2086. {
  2087.  char szString[256];
  2088.  LPNETCLIENT lpNetClient;
  2089.  
  2090.  wsprintf((LPSTR)szString, (LPSTR)"NetClientError(%d) - Begin", iError);
  2091.  DEBUGNETC((LPSTR)szString);
  2092.  
  2093.  if(!iError) return(ERR_None);
  2094.  
  2095.  if(iError == WSANO_DATA) return(ERR_None);
  2096.  
  2097.  lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  2098.  lpNetClient->sErrorNumber=(SHORT)iError;
  2099.  
  2100.  DEBUGNETC((LPSTR)"NetClientError() - Fire OnError()");
  2101.  
  2102.  return(clientFireOnError(hCtl));
  2103. } /* NetClientError() */
  2104.  
  2105.  
  2106. /* ERR clientFireOnConnect(HCTL);
  2107.     Purpose: To fire the OnRecv event.
  2108.     Given:   The control handle
  2109.     Returns: Any error condition
  2110. */
  2111. ERR clientFireOnConnect(HCTL hCtl)
  2112. {
  2113.  DEBUGNETC((LPSTR)"clientFireOnConnect()");
  2114.  return(VBFireEvent(hCtl, IEVENT_NETCLIENT_ONCONNECT, NULL));
  2115. } /* clientFireOnConnect() */
  2116.  
  2117.  
  2118. /* ERR clientFireOnRecv(HCTL);
  2119.     Purpose: To fire the OnRecv event.
  2120.     Given:   The control handle
  2121.     Returns: Any error condition
  2122. */
  2123. ERR clientFireOnRecv(HCTL hCtl)
  2124. {
  2125.  DEBUGNETC((LPSTR)"clientFireOnRecv()");
  2126.  return(VBFireEvent(hCtl, IEVENT_NETCLIENT_ONRECV, NULL));
  2127. } /* clientFireOnRecv() */
  2128.  
  2129.  
  2130. /*ERR clientFireOnSend(HCTL);
  2131.     Purpose: To fire the OnSend event.
  2132.     Given:   The control handle
  2133.     Returns: Any error condition
  2134. */
  2135. ERR clientFireOnSend(HCTL hCtl)
  2136. {
  2137.  DEBUGNETC((LPSTR)"clientFireOnSend()");
  2138.  return(VBFireEvent(hCtl, IEVENT_NETCLIENT_ONSEND, NULL));
  2139. } /* clientFireOnSend() */
  2140.  
  2141.  
  2142. /* ERR clientFireOnClose(HCTL);
  2143.     Purpose: To fire the OnClose event.
  2144.     Given:   The control handle
  2145.     Returns: Any error condition
  2146. */
  2147. ERR clientFireOnClose(HCTL hCtl)
  2148. {
  2149.  LPNETCLIENT lpNetClient;
  2150.  ERR err;
  2151.  
  2152.     // Dereference the control so we can look inside
  2153.  lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  2154.  
  2155.     // Make sure our app has the chance to handle ALL data
  2156.  if(lpNetClient->sRecvCount)
  2157.  {
  2158.   DEBUGNETC((LPSTR)"clientFireOnClose() - calling clientFireOnRecv()");
  2159.   err=clientFireOnRecv(hCtl);
  2160.   if(err) return(err);
  2161.  }
  2162.  return(VBFireEvent(hCtl, IEVENT_NETCLIENT_ONCLOSE, NULL));
  2163. } /* clientFireOnClose() */
  2164.  
  2165.  
  2166. /* ERR clientFireOnTimeOut(HCTL);
  2167.     Purpose: To fire the OnTimeOut event.
  2168.     Given:   The control handle
  2169.     Returns: Any error condition
  2170. */
  2171. ERR clientFireOnTimeOut(HCTL hCtl)
  2172. {
  2173.  DEBUGNETC((LPSTR)"clientFireOnTimeOut()");
  2174.  return(VBFireEvent(hCtl, IEVENT_NETCLIENT_ONTIMEOUT, NULL));
  2175. } /* clientFireOnTimeOut() */
  2176.  
  2177.  
  2178. /* ERR clientFireOnError(HCTL);
  2179.     Purpose: To fire the OnError event.
  2180.     Given:   The control handle
  2181.     Returns: Any error condition.
  2182. */
  2183. ERR clientFireOnError(HCTL hCtl)
  2184. {
  2185.  ONERRORPARMS Parameters;
  2186.  LPNETCLIENT lpNetClient;
  2187.  SHORT       sErrorNumber;
  2188.  
  2189.     // Dereference the control so we can look inside
  2190.     // Becomes invalid after the first VBLockHsz() below!
  2191.  DEBUGNETC((LPSTR)"clientFireOnError() - Begin");
  2192.  lpNetClient=(LPNETCLIENT)VBDerefControl(hCtl);
  2193.  
  2194.  sErrorNumber=lpNetClient->sErrorNumber;
  2195.  
  2196.     // Set the error number
  2197.  Parameters.ErrorNumber=(SHORT FAR *)&sErrorNumber;
  2198.  
  2199.  return(VBFireEvent(hCtl, IEVENT_NETCLIENT_ONERROR, (LPVOID)&Parameters));
  2200. } /* clientFireOnError() */
  2201.  
  2202. /* End of NetClnt.C */
  2203.  
  2204.